package lx.simpletinkerdemo;

import android.annotation.TargetApi;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.multidex.MultiDex;
import android.util.Log;

import com.tencent.tinker.anno.DefaultLifeCycle;
import com.tencent.tinker.lib.service.PatchResult;
import com.tencent.tinker.loader.app.DefaultApplicationLike;
import com.tencent.tinker.loader.shareutil.ShareConstants;
import com.tinkerpatch.sdk.TinkerPatch;
import com.tinkerpatch.sdk.tinker.callback.ResultCallBack;


/**
*
*@author LiXaing
*create at 2017/3/1 17:30
*/
@SuppressWarnings("unused")
@DefaultLifeCycle(
        application = "lx.simpletinkerdemo.ApplicationTest",//这里将lx.simpletinkerdemo.ApplicationTest更改为你自己的包名即可
        flags = ShareConstants.TINKER_ENABLE_ALL,
        loadVerifyFlag = false)  //tinkerFlags above

public class SampleApplicationLike extends DefaultApplicationLike {
    private static final String TAG = "Tinker.SampleAppLike";

    public SampleApplicationLike(Application application,
                                 int tinkerFlags,
                                 boolean tinkerLoadVerifyFlag,
                                 long applicationStartElapsedTime,
                                 long applicationStartMillisTime,
                                 Intent tinkerResultIntent
    ) {
        super(
                application,
                tinkerFlags,
                tinkerLoadVerifyFlag,
                applicationStartElapsedTime,
                applicationStartMillisTime,
                tinkerResultIntent
        );
    }

    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    @Override
    public void onBaseContextAttached(Context base) {
        super.onBaseContextAttached(base);
//初始化热修复
        MultiDex.install(base);
        initTinker();
    }



    private void initTinker() {
        TinkerPatch.init(this)
                //是否自动反射Library路径,无须手动加载补丁中的So文件
                //注意,调用在反射接口之后才能生效,你也可以使用Tinker的方式加载Library
                .reflectPatchLibrary()
                        //设置补丁合成成功后,锁屏重启程序
                        //默认是等应用自然重启
                .setPatchRestartOnSrceenOff(true)
                        //我们可以通过ResultCallBack设置对合成后的回调
                        //例如弹框什么
                .setPatchResultCallback(new ResultCallBack() {
                    @Override
                    public void onPatchResult(PatchResult patchResult) {
                        Log.i("TAG", "onPatchResult callback here");
                    }
                })
                        //默认是等主进程重启时自动清除
                .setPatchRollbackOnScreenOff(true);
    }
}